package com.fourth.controller;


import com.fourth.dto.Result;
import com.fourth.service.ICardBindingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 银行卡表 前端控制器
 * </p>
 *
 * @author 邓建波
 * @since 2022-08-04
 */
@Api("绑定卡相关")
@RestController
@RequestMapping("/card-binding")
public class CardBindingController {

    @Autowired
    private ICardBindingService cardBindingService;

    /**
     * 核对输入的验证码是否正确，正确则将卡绑定到用户下
     *
     * @param
     * @return
     */
    @ApiOperation(value = "将新卡绑定到用户名下", notes = "绑定前会验证之前发送给手机的验证码是否正确")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userPhone", value = "用户手机号", paramType = "Long", required = true),
            @ApiImplicitParam(name = "cardId", value = "银行卡号", required = true),
            @ApiImplicitParam(name = "bankName", value = "银行名称", required = true),
            @ApiImplicitParam(name = "saveNewCardDTO", value = "以上信息封装到该dto")
    })
    @GetMapping("/save-new-card/{Bank_Card_Id}/{User_Phone}/{Open_Bank}")
    public Result saveNewCard(@PathVariable("Bank_Card_Id") String Bank_Card_Id, @PathVariable("User_Phone") String User_Phone,
                              @PathVariable("Open_Bank") String bank) {
        return Result.ok("绑定成功", cardBindingService.saveNewCard(bank, User_Phone, Bank_Card_Id));
    }

    /**
     * 将卡绑定记录删除
     *
     * @param cardId
     * @return
     */
    @ApiOperation(value = "将卡绑定记录删除", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cardId", value = "银行卡号", required = true),
            @ApiImplicitParam(name = "accountPassword", value = "支付密码", required = true)
    })
    @GetMapping("/unbind-card/{cardId}/{accountPassword}")
    public Result unbindCard(@PathVariable("cardId") String cardId, @PathVariable("accountPassword") String accountPassword) {
        return Result.ok("解绑成功", cardBindingService.deleteCard(cardId, accountPassword));
    }

    /**
     * 获取银行卡信息
     *
     * @param Bank_Card_Id 银行卡Id
     * @return Result
     */
    @ApiOperation(value = "获取银行卡信息", notes = "在用户输入银行卡号后获取银行卡信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cardId", value = "银行卡号", required = true)
    })
    @GetMapping("/getBankMsg/{Bank_Card_Id}")
    public Result getBankMsg(@PathVariable("Bank_Card_Id") String Bank_Card_Id) {
        return Result.ok("获取银行卡信息成功", cardBindingService.getBankMsg(Bank_Card_Id));
    }

    /**
     * 获取银行卡信息开户信息
     *
     * @param Bank_Card_Id
     * @return
     */
    @ApiOperation(value = "获取银行卡开户信息", notes = "在用户输入银行卡号后获取银行卡信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cardId", value = "银行卡号", required = true)
    })
    @GetMapping("/getPwd/{Bank_Card_Id}/{User_Phone}")
    public Result getPwd(@PathVariable("Bank_Card_Id") String Bank_Card_Id, @PathVariable("User_Phone") String User_Phone) {
        return Result.ok("获取银行卡信息成功", cardBindingService.getPwd(Bank_Card_Id, User_Phone));
    }

    /**
     * 发送验证码
     *
     * @param User_Phone
     * @return
     */
    @ApiOperation(value = "发送验证码", notes = "向对应手机号发送验证码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "User_Phone", value = "用户手机号", required = true)
    })
    @GetMapping("/sendValidCode/{User_Phone}")
    public Result sendValidCode(@PathVariable("User_Phone") String User_Phone) {
        System.out.println(User_Phone + "正在发送");
        cardBindingService.sendValidCode(User_Phone);
        return Result.ok("发送成功");
    }

}
